const Mock = require('mockjs');
const getQuestionList = require("./getQuestionList");

const Random = Mock.Random

module.exports = [{

    url: "/api/questions/:id",
    method: "get",
    response() {
        return {
            errno: 0,
            data: {
                id: Random.id(),
                title: Random.ctitle(),
                componentList: [{
                    id: Random.id(),
                    type: 'questionTitle',
                    title: '标题',
                    props: {test: '个人信息调研', level: 1, isCenter: false}
                }, {
                    id: Random.id(),
                    type: 'questionInput',
                    title: '输入框',
                    props: {title: '你的姓名', placeholder: '请输入姓名....'}
                }]
            }
        }
    }
}, {
    //创建问卷
    url: "/api/questions",
    method: "post",
    response() {
        return {
            errno: 0,
            data: {
                id: Random.id(),
            }
        }
    }
}, {
    //查询
    url: "/api/questions",
    method: "get",
    response(ctx) {
        const {url = '', query = {}} = ctx
        const isDeleted = url.indexOf("isDeleted=true") >= 0;
        const isStar = url.indexOf("isStar=true") >= 0;
        const pageSize = query.pageSize || 10;

        return {
            errno: 0,
            data: {

                list: getQuestionList({len: pageSize, isDeleted, isStar}),
                total: 100,
            }
        }
    }
}, {
    //修改
    url: "/api/questions/:id",
    method: "patch",
    response() {
        return {
            errno: 0
        }
    }
}, {
    //复制
    url: "/api/questions/duplicate/:id",
    method: "post",
    response() {
        return {
            errno: 0,
            data: {
                id: Random.id(),
            }
        }
    }
}, {
    //彻底删除
    url: "/api/questions/",
    method: "delete",
    response() {
        return {
            errno: 0
        }
    }
}
]